int* findDuplicates(int* nums, int numsSize, int* returnSize) {
    for (int i = 0; i < numsSize; ++i) {
        while (nums[i] != nums[nums[i] - 1]) {
            int tmp = nums[i];
            nums[i] = nums[tmp - 1];
            nums[tmp - 1] = tmp;
        }
    }
    int *ans = (int *)malloc(sizeof(int) * numsSize);
    int pos = 0;
    for (int i = 0; i < numsSize; ++i) {
        if (nums[i] - 1 != i) {
            ans[pos++] = nums[i];
        }
    }
    *returnSize = pos;
    return ans;
}

